package com.example.j2025_11_10.service;

import com.example.j2025_11_10.Model.BookInfo;
import com.example.j2025_11_10.Model.PageInfo;
import com.example.j2025_11_10.Model.PageResult;
import com.example.j2025_11_10.mapper.GetBookByPageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

//获取图书列表信息
@Service
public class GetListByPageService {
    @Autowired
    private GetBookByPageMapper getBookByPageMapper;
    private PageResult<BookInfo> pageResult;
    public PageResult<BookInfo> getListByPage(PageInfo pageInfo){

        Integer count = getBookByPageMapper.getCount();
        List<BookInfo> bookInfoList = getBookByPageMapper.getList(pageInfo);
        //设置借阅状态
        for (BookInfo book : bookInfoList) {
            if (book.getStatus() == 1) {
                book.setStatusCN("可借阅");
            } else {
                book.setStatusCN("不可借阅");
            }
        }
        pageResult = new PageResult<BookInfo>(count,bookInfoList,pageInfo);
        return pageResult;
    }

}
